package org.lsms.servlet;

/**
 * servlet invoked when admin release a new note
 * @author ZhanXueliang
 * 2010.9.10
 */

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lsms.bean.News;
import org.lsms.dao.impl.DaoImpl;

public class release_new_note extends HttpServlet {

	public void destroy() {
		super.destroy();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			this.doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

			String title = request.getParameter("title");
			String content = request.getParameter("content");
			int is_top = Integer.parseInt(request.getParameter("is_top"));
			
			News news = new News();
			news.setNews_content(content);
			news.setNews_is_top(is_top);
			news.setNews_title(title);
			
			DaoImpl impl = new DaoImpl();
			
			if(impl.release_new_note(news)){
				String info = "The new note has been released!";
				response.sendRedirect("admin/admin_show_info.jsp?admin_info="+info);
				return;
			}else{
				String info = "Problem occurs when relaese new note!Try again later.";
				response.sendRedirect("admin/admin_show_info.jsp?admin_info="+info);
				return;
			}
	}

	
	public void init() throws ServletException {
		// Put your code here
	}

}
